<?php
include('../../__global.php');
include(SERVER_ROOT_PATH.'/include/config/ml_catelog.php');

class aj_scroll_commentme extends ml_controller
{
    private $page;
    private $segment;
    public function initParam()
    {
        $this->page = intval($this->input('page' , 'g' , 1));
        $this->segment= intval($this->input('segment' , 'g' , 2));
    }
    public function checkParam()
    {
        $this->check_referer();
        if(!$this->check_permission(ML_PERMISSION_LOGIN_ONLY)) {
            return $this->api_output(ML_RCODE_NOLOGIN);
        }
        else if(!$this->check_permission(ML_PERMISSION_LOGIN_CANWRITE)) {
            return $this->api_output(ML_RCODE_NOACTIVE);
        }
    }
    public function main()
    {
        $oComment= new ml_model_dbComment();
        $uid = $this->__visitor['uid'];
        $data = array();
        $begin=($this->page -1 )* ML_FEED_PAGESIZE * 3 + ($this->segment -1)*ML_FEED_PAGESIZE;
        
        $rs = $oComment->getCommentsByUid($uid ,$begin, ML_FEED_PAGESIZE);
        if(!$rs)
            $this->redirect(ML_PAGE_SYSTEM_BUSY);
                
        $aRows = $oComment->get_data();
        
        $comOut=new ml_biz_feed_commentMe();
        $aHtml=$comOut->getComHtml($aRows);
        
        $data['items']=$aHtml;
        
        $total=$oComment->getComCountByUid($uid);
        $total=$oComment->get_data();
        
        $data['lastSegment']=false;
        if( $this->segment >=3  || $total['num'] <= ($this->page -1)*ML_FEED_PAGESIZE*3 + ($this->segment)*ML_FEED_PAGESIZE){
            $data['lastSegment']=true;
        }
        
        $this->api_output(ML_RCODE_SUCC ,$data);
    }
    
}
new aj_scroll_commentme();